package user.dao;

import java.sql.SQLException;
import java.util.List;

import user.vo.User;
import utils.JDBCUtils;

public class UserDao extends JDBCUtils{

	public User validate(String username, String password) throws SQLException, IllegalArgumentException, IllegalAccessException, InstantiationException {
		con = getConnction();
		String sql = "select * from user where username=? and password = ?";
		pst = con.prepareStatement(sql);
		pst.setString(1, username);
		pst.setString(2, password);
		res = pst.executeQuery();
		List list = populate(res,User.class);
		if(list.size()>0 && list!=null){
			return (User) list.get(0);
		}
		return null;
	}

	public boolean insert(String name,String password) throws SQLException {
		con = getConnction();
		String sql = "insert into  user(username,password,type) value(?,?,?)";
		pst = con.prepareStatement(sql);
		pst.setString(1, name);
		pst.setString(2, password);
		pst.setString(3, "user");
		boolean bool = pst.execute();
		return bool;
	}

}
